import $copy from '@utils/copy'
import onInit from '../_utils/edit'
import { dataTypeData } from './data-type'
// const { $fn, $http } = window

const Index = ({ table_name, folder }) => ({
	modal: {
		title 		: table_name,
		width 		: '100%',
		height 		: '100%',
		maxWidth 	: null,
		controls 	: {
			after: [
				{ label:'删除建表文件', ghost:1, mode:'confirm', msg:`确认删除表 【${table_name}】?`, way:'post', 
					api:'file/remove', param: { folder, table_name },
					onOk: () => {
						window.$formModalRef().close()
					}
				},
				// { label:'保存 Model', ghost:1, click: () => {
				// 	const model = window.$formModalRef().formRef().getValue('model')
				// 	if( $fn.isEmpty(model) ) return $fn.msg.success(`Model 数据模型【${table_name}】不能为空`)
				// 	$http.post(null, 'file/save_model', { param: { folder, table_name, model} }).then(()=>{
				// 		$fn.msg.success(`Model 数据模型【${table_name}】保存成功`)
				// 		$http.post(null, 'mysql/table_record/del', { param: { id:table_name, database } }).then(()=>{
				// 			$fn.msg.success(`删除表【${table_name}】保存成功`)
				// 			onRefresh()
				// 		})
				// 	})
				// } },
				{ label:'复制 Table', ghost:1, click: () => $copy( window.$formModalRef().formRef().getValue('table') ) },
				// { label:'复制 Model', ghost:1, click: () => $copy( window.$formModalRef().formRef().getValue('model') ) }
				{ label:'复制数据类型', ghost:1, mode:'dropdown', data:dataTypeData, change: ({ value }) => {
					$copy(value)
				} },
			],
			ok: { label:'保存 Tabel' },
		}
	},
	form: {
		labelWidth 	: 's3',
		className 	: 'pre-form',
		api 		: 'file/save_table',
		infoApi 	: 'file/read_table',
		param 		: { folder, table_name},
		setParam 	: () => ({ model: null }),
		backParam 	: { folder, table_name },
		okTxt 		: `表【${table_name}】保存成功`,
		// close 		: false,
		data: [
			{ name:'table', type:'textarea', maxLength: null, p:'Table', r:1, _label: 'Table 表', class:'jz-table-textarea' },
			// { name:'model', type:'textarea', maxLength: null, p:'Model', class:'jz-model-textarea'},
		],
		onInit: () => {
			onInit('.jz-table-textarea')
			onInit('.jz-model-textarea')
		}
	}
})
export default Index